package com.example.demo.repository;

import com.example.demo.bean.response.DynamicListResponse;
import com.example.demo.table.DynamicTable;
import com.example.demo.table.UserTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DynamicRepository extends JpaRepository<DynamicTable,Integer> {

    List<DynamicTable> findByUserID(int userId);

    @Query(value = "select new com.example.demo.bean.response.DynamicListResponse(user.avatar,user.nickName,dy.dynamicCreateTime,dy.pictureSet,dy.label,dy.content)  from DynamicTable dy left join UserTable user ON user.userID = dy.userID where dy.userID = :userID")
    List<DynamicListResponse> selectDynamicList(@Param("userID") Integer userID);

    @Query(value = "select new com.example.demo.bean.response.DynamicListResponse(user.avatar,user.nickName,dy.dynamicCreateTime,dy.pictureSet,dy.label,dy.content)  from DynamicTable dy left join UserTable user ON user.userID = dy.userID")
    List<DynamicListResponse> selectAllDynamicList();

}
